package org.systm.menu.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.global.GEntity;
import org.global.basic.tree.TreeItem;
import org.global.basic.tree.TreeMeta;

import javax.persistence.*;

/**
 * 菜单
 */

@Getter
@Setter
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "sys_menu")
public class Menu extends GEntity<String> implements TreeMeta {
    @Column(columnDefinition = "varchar(50) not null comment '访问URL'")
    private String path;

    @Column(columnDefinition = "varchar(50) comment '重定向url'")
    private String redirect;

    @Column(columnDefinition = "varchar(100) not null comment '组件路径'")
    private String component;

    @Column(columnDefinition = "varchar(50) comment '路由名字 / 权限名字'")
    private String name;

    @Column(columnDefinition = "varchar(36) comment '父级'")
    private String pid;

    @Column(columnDefinition = "int default 0 comment '排序'")
    private int sort;

    @Convert(converter = MenuType.Convert.class)
    @Column(columnDefinition = "varchar(20) not null comment '导航类型'")
    private MenuType menuType;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(
            foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT),
            referencedColumnName = "id",
            name = "meta_id"
    )
    private PageMeta meta;

    @Override
    @JsonIgnore
    @Transient
    public String pid() {
        return this.pid;
    }

    @Override
    @JsonIgnore
    @Transient
    public String id() {
        return super.getId();
    }
}
